/**
 * Created by WUJO5 on 3/22/2018.
 */

var _ = require('lodash');

var getFilterPageList = function (data,result,success) {
    var total = result.length;
    var maxIndex = data.pageSize * data.page;
    var minIndex = data.pageSize * (data.page - 1);
    var newResult = result.filter((currentValue,index)=> index < maxIndex && index >= minIndex);
    success({data:newResult,total:total});
}

var replaceSourceDataWithKeyValue = function (data, bizKeys) {
    if(data && bizKeys){
        bizKeys.forEach(function (bizKey) {
            var res = "@" + bizKey.bizKeyType + "@";
            data = data.replace(new RegExp(res, 'g'), bizKey.bizKeyValue);
        }, this);
    }
    return data;
};

module.exports = {
    getFilterPageList : getFilterPageList,
    replaceSourceDataWithKeyValue : replaceSourceDataWithKeyValue
}